//
//  HYLPerson.m
//  单例模式
//
//  Created by hyl on 16/7/18.
//  Copyright © 2016年 hyl. All rights reserved.
//

#import "HYLPerson.h"

@interface HYLPerson () <NSCopying>

@end

@implementation HYLPerson

//alloc还会再去调用allocWithZone
+(instancetype)alloc{
    NSLog(@"%s",__func__);
    return [super alloc];
}
//公在这个类里有效
static HYLPerson *_person;
+(instancetype)allocWithZone:(struct _NSZone *)zone{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _person=[super allocWithZone:zone];
    });
    return _person;
}

//因为拷贝之前肯定有对象，所以直接拿来用
-(id)copyWithZone:(NSZone *)zone{
    return _person;
}

+(instancetype) sharePerson{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _person=[[HYLPerson alloc]init];
    });
    return _person;
}
@end
